// ClientConfiguration.cpp: implementation of the ClientConfiguration class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ClientConfiguration.h"

#include "CommonLib\Registry.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

ClientConfiguration::ClientConfiguration():
m_strServerIPAddress(""),
m_nPort(0),
m_nNetworkMode(LAN),
m_strUserName(""),
m_strPassword(""),
m_dwPermission(0),
m_bHideLoginDlg(false),
m_bEmbeddedMode(false),
m_ptSelectDlgTopLeft(0, 0)
{

}

ClientConfiguration::~ClientConfiguration()
{
    
}

ClientConfiguration * ClientConfiguration::m_pInstance = NULL;

ClientConfiguration * ClientConfiguration::Instance()
{
  if (m_pInstance == NULL)
  {
    m_pInstance = new ClientConfiguration;
  }

  return m_pInstance;
}

void ClientConfiguration::DeleteInstance()
{
  if (m_pInstance != NULL) delete m_pInstance;

  m_pInstance = NULL;
}

void ClientConfiguration::Init()
{
  m_strRegistryEntry = "SOFTWARE\\Eflong\\KWSystem\\1.0\\";

  Registry reg(m_strRegistryEntry);

  m_strUserName = reg.Read("Client", "UserName", "");
  m_strServerIPAddress = reg.Read("Client", "ServerIPAddr", "");
  m_nNetworkMode = reg.Read("Client", "NetworkMode", 0);
  m_ptSelectDlgTopLeft = reg.Read("Client", "SelectDlgTopLeft", MAKELONG(-1000, -1000));
  m_ptAlarmAnimWndTopLeft = reg.Read("Client", "AlarmAnimWndTopLeft", MAKELONG(-1000, -1000));
}

void ClientConfiguration::Cleanup()
{
  Registry reg(m_strRegistryEntry);
  reg.Write("Client", "SelectDlgTopLeft", MAKELONG(m_ptSelectDlgTopLeft.x, m_ptSelectDlgTopLeft.y));
  reg.Write("Client", "AlarmAnimWndTopLeft", MAKELONG(m_ptAlarmAnimWndTopLeft.x, m_ptAlarmAnimWndTopLeft.y));
}
